local langgu = fk.CreateSkill{
  name = "iberia__langgu",
  tags = { "HegSwitch" },
}

Fk:loadTranslationTable{
  [langgu.name] = "狼顾",
  [":"..langgu.name] = "转换技，当你区域内的牌进入弃牌堆后，"
  .."阴：你可以弃置当前回合角色一张牌；"
  .."阳：你可以使用其中一张【杀】。",

  ["#iberia__langgu-yin"] = "狼顾（阴）：可以弃置 %dest 一张牌",
  ["#iberia__langgu-yang"] = "狼顾（阳）：你可以使用其中的一张【杀】",
}

local I = require "packages/iberia/utility"

langgu:addEffect(fk.AfterCardsMove, { -- Yin
  anim_type = "switch",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(langgu.name) or not player:isFakeSkill(langgu.name) then return end
    for _, move in ipairs(data) do
      if move.from == player and move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea <= Card.PlayerJudge then
            return true
          end
        end
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    return player.room:askToSkillInvoke(player, {
      skill_name = langgu.name,
      prompt = "#iberia__langgu-yin::"..player.room.current.id
    })
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    room:throwCard(room:askToChooseCard(player, {
      target = room.current,
      flag = "he",
      skill_name = langgu.name,
    }), langgu.name, room.current, player)
  end
})

langgu:addEffect(fk.AfterCardsMove, { -- Yang
  anim_type = "switch",
  can_trigger = function (self, event, target, player, data)
    if not player:hasSkill(langgu.name) or player:isFakeSkill(langgu.name) then return end
    local slashs = {}
    for _, move in ipairs(data) do
      if move.from == player and move.toArea == Card.DiscardPile then
        for _, info in ipairs(move.moveInfo) do
          if info.fromArea <= Card.PlayerJudge then
            if Fk:getCardById(info.cardId).trueName == "slash" then
              table.insert(slashs, info.cardId)
            end
          end
        end
      end
    end
    if #slashs > 0 then
      event:setCostData(self, slashs)
      return true
    end
  end,
  on_cost = function (self, event, target, player, data)
    local room = player.room
    local slashs = event:getCostData(self)
    local use = room:askToUseRealCard(player, {
      pattern = tostring(Exppattern { id = slashs }),
      prompt = "#iberia__langgu-yang",
      extra_data = { expand_pile = slashs, bypass_times = true },
      skip = true,
    })
    if use then
      event:setCostData(self, use)
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    S.hideGeneralBySkill(player, langgu.name)
    player.room:useCard(event:getCostData(self))
  end
})

return langgu